package com.woniuxy02;

import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-08-28 15:57
 */
public class Test03 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("是否开始游戏y/n");
        String answer = sc.next();
        int random;
        int num, count = 1;
        boolean flag = false;
        while (answer.equals("y")) {
            //归零
            count=1;
            //归零
            flag = false;
            //归零
            random = (int) (Math.random() * 100);
            System.out.println("random=" + random);
            do {
                System.out.println("第" + count + "次，输入你猜到数字");
                num = sc.nextInt();
                if (num > random) {
                    System.out.println("猜大了");
                } else if (num < random) {
                    System.out.println("猜小了");
                } else {
                    flag = true;
                    break;
                }
                count++;
                if (count > 3) {
                    break;
                }
            } while (true);

            if (flag) {
                System.out.println("恭喜你，猜对了");
            } else {
                System.out.println("三次机会用完了，游戏结束");
            }


            System.out.println("是否继续y/n");
            answer = sc.next();
        }
        System.out.println("程序结束");


    }
}
